package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.poi.StringUtils;
import com.bwie.pojo.THy;
import com.bwie.service.THyService;
import com.bwie.mapper.THyMapper;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
* @author 28463
* @description 针对表【t_hy】的数据库操作Service实现
* @createDate 2025-06-17 11:05:45
*/
@Service
public class THyServiceImpl extends ServiceImpl<THyMapper, THy>
    implements THyService{
    @Autowired
    THyMapper tHyMapper;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Override
    public R listHY(PageInfoVo pageInfoVo) {
        Page<THy> tHyPage = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());
        QueryWrapper<THy> wrapper = new QueryWrapper<>();
       if(!StringUtils.isEmpty(pageInfoVo.getHyName())){
           wrapper.lambda().like(THy::getHyName,pageInfoVo.getHyName());
       }
       if(pageInfoVo.getHyStatus()!=null){
           wrapper.lambda().eq(THy::getHyStatus,pageInfoVo.getHyStatus());
       }
       if(!StringUtils.isEmpty(pageInfoVo.getHyAddr())){
           wrapper.lambda().like(THy::getHyAddr,pageInfoVo.getHyAddr());
       }
        if(pageInfoVo.getHySex()!=null){
            wrapper.lambda().eq(THy::getHySex,pageInfoVo.getHySex());
        }
        if(pageInfoVo.getHyHy()!=null){
            wrapper.lambda().eq(THy::getHyHy,pageInfoVo.getHyHy());
        }

        Page<THy> tHyPage1 = tHyMapper.selectPage(tHyPage, wrapper);
        return R.OK(tHyPage1);
    }

    @Override
    public R deleteHY(String hyId) {
        tHyMapper.deleteById(hyId);
        return R.OK();
    }

    @Override
    public R addHY(THy tHy) {
        tHyMapper.insert(tHy);

        stringRedisTemplate.opsForValue().set("addHy","",5, TimeUnit.MINUTES);
        return R.OK();
    }

}




